#include<iostream>
using namespace std;
typedef struct node{
    struct node* prior;
    int data;
    struct node* next;
    }Node;//数据类型的定义
class Linknode{
    public:
    Node* head;
    int length;
    int isempty();
    Linknode();
    void headinsert(int data);
    void tailinsert(int data);
    void delectlist(int data);
    void clearList();
    void showList();
};
int main(){
    Linknode L;
    L.headinsert(1);
    L.headinsert(2);
    L.headinsert(3);
    L.headinsert(4);
    L.headinsert(5);
    L.headinsert(6);
    L.headinsert(7);
    L.headinsert(8);
    L.tailinsert(99);
    L.tailinsert(123);
    L.headinsert(111);
    L.showList();
    cout<<"请输入你要删除的数字"<<endl;
    int data;
    cin>>data;
    L.delectlist(data);
    cout<<"删除后"<<endl;
    L.showList();
    return 0;
}
Linknode::Linknode(){
    this->head=new Node;
    this->head->data=0;
    this->head->prior=head;
    this->head->next=head;
    this->length=head->data;
}
void Linknode::showList(){
        cout<<"链表中的元素个数为"<<head->data<<endl;
        Node* pstr=this->head->next;
        for(;pstr!=head;pstr=pstr->next){
            if(pstr==this->head->next){
                cout<<" "<<pstr->data;
            }
            else{
                cout<<"->"<<pstr->data;
            }
        }

}
int Linknode::isempty(){
    if(this->head->data==0){
        return 1;
    }
    else{
        return 0;
    }
}
void Linknode::headinsert(int data){
        Node* pnew=new Node;
        pnew->data=data;
        pnew->prior=head;
        pnew->next=head->next;
        head->next->prior=pnew;
        head->next=pnew;
        head->data++;
}
void Linknode::tailinsert(int data){
        Node* pstr=head->next;
        while(pstr->next!=head){
            pstr=pstr->next;
        }
        Node* pnew=new Node;
        pnew->data=data;
        pstr->next=pnew;
        pnew->prior=pstr;
        pnew->next=head;
        head->prior=pnew;
        head->data++;
}
void Linknode::delectlist(int data){
    if(this->isempty()==1){
        cout<<"链表为空,删除失败"<<endl;        
    }
   else{ Node* pstr=head->next;
    for(;pstr!=head;pstr=pstr->next){
        if(pstr->data==data){
            pstr->prior->next=pstr->next;
            pstr->next->prior=pstr->prior;
        }
    }
        head->data--;
   }
}
void Linknode::clearList(){
    this->head->data=0;
    this->head->prior=head;
    this->head->next=head;
}